package org.yinxue.framework.jdbc.mysql;

import org.yinxue.framework.jdbc.JdbcClient;
import org.yinxue.framework.jdbc.datasource.YXDataSource;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class MySqlJdbcClient extends JdbcClient {

    private String username;
    private String password;
    private String url;
    private static final String DEFAULT_JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";

    public MySqlJdbcClient(String username, String password, String url) {
        super(new YXDataSource(username, password, url, DEFAULT_JDBC_DRIVER));
    }

    public List<Table> queryTables() throws Exception {
        List<Map<String, Object>> results = this.doQueryListOfMap("SELECT TABLE_NAME,TABLE_SCHEMA FROM tables");
        return results.stream().map(result -> {
            Table table = new Table();
            table.setTableName((String) result.get("TABLE_NAME"));
            table.setTableSchema((String) result.get("TABLE_SCHEMA"));
            return table;
        }).collect(Collectors.toList());
    }

    public void createTable() {

    }
}
